/*
package com.lifeng.es.client;

import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.get.MultiGetItemResponse;
import org.elasticsearch.action.get.MultiGetResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.reindex.BulkByScrollResponse;
import org.elasticsearch.index.reindex.DeleteByQueryAction;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;

*/
/**
 * Created by lifeng on 2019/4/25.
 *//*

@Service
public class TransportClientService {
    @Resource(name="transportClientOne")
    private TransportClient client;
    */
/**
     * 创建索引并添加映射
     * *//*

    public CreateIndexResponse createIndexAndMapping(String indexName,String type) throws Exception {
        CreateIndexRequestBuilder cib = client.admin().indices().prepareCreate(indexName);
        //构建mapping
        XContentBuilder mapping = jsonBuilder()
                .startObject()
                    .startObject("properties") //设置之定义字段
                        .startObject("author")
                            .field("type","text") //设置数据类型同时是text有是keyword
                            .startObject("fields")
                                .startObject("keyword")
                                    .field("type","keyword")
                                    .field("ignore_above",256)
                                .endObject()
                            .endObject()
                        .endObject()
                        .startObject("title")
                            .field("type","text")
                        .endObject()
                        .startObject("content")
                            .field("type","text")
                            */
/*
                            es5.0后只有这两种
                            *  ik_max_word: 会将文本做最细粒度的拆分，比如会将“我是中国人”拆分为“我，是，中国人，中国，国人”，会穷尽各种可能的组合。
                                ik_smart: 会做最粗粒度的拆分，比如会将“我是中国人”拆分为“我，是，中国人”。
                            * *//*

                            .field("analyzer","ik_max_word")
                        .endObject()
                        .startObject("price")
                            .field("type","float")
                        .endObject()
                        .startObject("view")
                            .field("type","text")
                        .endObject()
                        .startObject("tag")
                            .field("type","text")
                        .endObject()
                        .startObject("publishdate")
                            .field("type","date")  //设置Date类型
                            .field("format","yyyy-MM-dd HH:mm:ss") //设置Date的格式
                        .endObject()
                    .endObject()
                .endObject();
        cib.addMapping(type, mapping);
        //cib.setSource(); //可以创建索引是添加数据
        CreateIndexResponse res = cib.execute().actionGet();
        //true 标识创建成功
        return res;
    }

    */
/**
     * 创建索引并添加数据
     * *//*

    public IndexResponse createIndexAndAddData(String index,String type) throws Exception {
        //构造索引数据
        XContentBuilder xContentBuilder = jsonBuilder()
                .startObject()
                    .field("id","447")
                    .field("author","张三")
                    .field("title","这是JAVA有关的书籍")
                    .field("content","需要一个字段既支持类似mysql的精确值匹配，又要支持全文检索")
                    .field("price","20")
                    .field("view","100")
                    .field("tag","a,b,c,d,e,f")
                    .field("date",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()))
                .endObject();

        IndexResponse response = client.prepareIndex(index, type).setSource(xContentBuilder).get();
        System.out.println(response);
        return response;
    }
    */
/**
     * 通过id删除
     * *//*

    public DeleteResponse deleteById(String index,String type,String id){
        DeleteResponse response = client.prepareDelete(index, type, id).get();
        return response;
    }

    */
/**
     * 通过条件删除
     * *//*

    public BulkByScrollResponse deleteByQueryString(String index){
        BulkByScrollResponse response = DeleteByQueryAction.INSTANCE.newRequestBuilder(client)
                .filter(QueryBuilders.matchQuery("author", "张三"))
                .source(index)
                .get();
        return response;
    }

    */
/**
     * 修改
     * *//*

    public UpdateResponse update(String index,String type,String id) throws Exception {
        UpdateResponse response = client.prepareUpdate(index,type,id)
                .setDoc(jsonBuilder()
                        .startObject()
                            .field("author", "王五")
                        .endObject())
                .get();
        return response;
    }

    */
/**
     * 根据id查询多条
     * *//*

    public void getByIds(String index,String type,String[] ids) throws Exception {
        MultiGetResponse multiGetItemResponses = client.prepareMultiGet()
                .add(index,type, ids)
                .get();
        for (MultiGetItemResponse itemResponse : multiGetItemResponses) {
            GetResponse response = itemResponse.getResponse();
            if (response.isExists()) {
                String json = response.getSourceAsString();
                System.out.println(json);
            }
        }
    }

    */
/**
     * 批量执行
     * *//*

    public BulkResponse batchAdd(String index,String type) throws Exception {
        BulkRequestBuilder bulkRequest = client.prepareBulk();
        bulkRequest.add(client.prepareIndex(index, type, new Date().getTime()+"")
                .setSource(jsonBuilder()
                        .startObject()
                            .field("user", "zhangsan")
                            .field("postDate", new Date())
                            .field("message", "trying out Elasticsearch")
                        .endObject()
                )
        );

        bulkRequest.add(client.prepareIndex(index, type, new Date().getTime()+2+"")
                .setSource(jsonBuilder()
                        .startObject()
                            .field("user", "lisi")
                            .field("postDate", new Date())
                            .field("message", "another post")
                        .endObject()
                )
        );

        BulkResponse bulkResponse = bulkRequest.get();
        return bulkResponse;
    }

    */
/**
     * 根据id查询多条
     * *//*

    public GetResponse getById(String index,String type,String id) throws Exception {
        GetResponse response = client.prepareGet(index, type,id).get();
        return response;
    }

    */
/**
     * https://blog.csdn.net/u011781521/article/details/77848489
     * *//*

}
*/
